<?php
class Test extends Zend_Nosql_Mongo_Db {	
	/*
	function callNoSql() {	
		// connect
		$m = new Mongo();

		// select a database
		$db = $m->comedy;

		// select a collection (analogous to a relational database's table)
		$collection = $db->cartoons;

		// add a record
		$obj = array( "title" => "Calvin and Hobbes", "author" => "Bill Watterson" );
		$collection->insert($obj);

		// add another record, with a different "shape"
		$obj = array( "title" => "XKCD", "online" => true );
		$collection->insert($obj);

		// find everything in the collection
		$cursor = $collection->find();

		// iterate through the results
		foreach ($cursor as $obj) {
			echo $obj["title"] . "<br/>";
		}
	}
	*/
	function callNoSql() {
		// connect to the daemon
$mongo = new Mongo();

// select the 'posts' collection
$collection = $mongo->selectDB('blog')->selectCollection('posts');

// create some sample posts
$post1 = array(
    'title'    => 'My fifth post',
    'content'  => 'This is the content of the fifth post',
    'comments' => array(
        'comment 1' => 'This is a sample comment',
        'comment 2' => 'This is another sample comment',
        'comment 3' => 'This is yet another sample comment'
    )
);

$post2 = array(
    'title'    => 'My sixth post',
    'content'  => 'This is the content of the sixth post',
    'comments' => array(
        'comment 1' => 'This is a sample comment',
        'comment 2' => 'This is another sample comment',
        'comment 3' => 'This is yet another sample comment'
    )
);

$post3 = array(
    'title'    => 'My seventh post',
    'content'  => 'This is the content of the seventh post',
    'comments' => array(
        'comment 1' => 'This is a sample comment',
        'comment 2' => 'This is another sample comment',
        'comment 3' => 'This is yet another sample comment'
    )
);

// insert the new posts

$collection->insert($post1);
$collection->insert($post2);
$collection->insert($post3);

// fetch all posts from the collection
$posts = $collection->find();

foreach ($posts as $post) {
    // display the posts
    echo 'Id: '      . $post['_id']     . '<br />
          Title: '   . $post['title']   . '<br />
          Content: ' . $post['content'] . '<br />';
     
    // display the related comments
    foreach ($post['comments'] as $key => $comment) {
        echo $key . ' ' . $comment . '<br />';
    }
    echo '<hr />';
}
	}
}
?>